﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BSC_OTC_Management.Forms
{
    public partial class Frm_Manage_group : Form
    {
        #region khai bao bien
        DataTable _tableTreeview = new DataTable();
        Code.StaticVariable _code = new Code.StaticVariable();
        # endregion            

        public Frm_Manage_group()
        {
            InitializeComponent();
            load_treeview();
            this.lblFooter.Text = "Tổng cộng có " + this._tableTreeview.Rows.Count.ToString() + " bản ghi";
            this.dgv.CellFormatting += new DataGridViewCellFormattingEventHandler(dgv_CellFormatting);
        }

        private void load_treeview()
        {
            this._tableTreeview = _code._services.GetData_AllGroups();
            AddTopMenu();
        }

        // Add menu Cha
        private void AddTopMenu()
        {
            this.treegroup.Nodes.Add("NhomQuyen", "Nhóm quyền");
            foreach (DataRow row in this._tableTreeview.Rows)
            {
                this.treegroup.Nodes[0].Nodes.Add(row["cdval"].ToString(), row["cdcontent"].ToString());
            }
            this.treegroup.ExpandAll();
        }

        // sự kiện click vào 1 nhóm
        private void treegroup_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Level == 1)
            {
                DataTable table = new DataTable("noname");
                table = this._code._services.Get_UsersByGroup(e.Node.Name);
                this.ShowUsersByGroup(table);
            }
        }

        private void ShowUsersByGroup(DataTable table)
        {
            this.dgv.DataSource = table;
        }

        void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex % 2 == 0)
            {
                e.CellStyle.BackColor = Color.FromArgb(195, 231, 195);
            }
            else
            {
                e.CellStyle.BackColor = Color.FromArgb(253, 240, 208);
            }
        }
    }
}
